<?php
namespace App\Http\Controllers\WebApi\UserCenter;

use Illuminate\Http\Request;
use App\Http\Controllers\WebApi\BaseController;
use App\Http\Service\CompanyService;

class MaterialController extends BaseController{
    protected $service;

    public function __construct()
    {
        parent::__construct();
        $this->service = new CompanyService();
    }
    
    public function test(){
        return "testMaterialController";
    }

    //判断是否有空数据提交上来
    public function validDataIsNotNull($data=[]){
        $flag = true;
        foreach ($data as $key=>$val){
            if($val==""){
                $flag = false;
                break;
            }
        }
        return $flag;
    }
    public function getDataDelToken($data=[]){
        array_splice($data, 0,1);
        return $data;
    }

        //获取法人信息
    public function getLegalInfoById(Request $request){
        $uid = $request->uid;
        //$uid = 12;
        $data = $this->service->getLegalInfoById($uid);
        if(!$data){
            return $this->tojson(-3);
        }
        return $this->success($data);
    }
    //保存法人信息
    public function saveLegalInfoById(Request $request){
        $data = $request->data;
        $uid = $request->uid;
        $validFlag = $this->validDataIsNotNull($data);//验证数据是否有空
        if(!$validFlag){
            return $this->toJson(-2);
        }
        //$data = $this->getDataDelToken($data);
        $flag = $this->service->saveLegalInfoById($uid,$data);
        if(!$flag){
            return $this->toJson(-100);
        }
        return $this->success();
    }
    //获取公司信息
    public function getCompanyInfoById(Request $request){
        $uid = $request->uid;
        //$uid = 12;
        $data = $this->service->getCompanyInfoById($uid);
        if(!$data){
            return $this->toJson(-3);
        }
        return $this->success($data);
    }
    //保存公司信息
    public function saveCompanyInfoById(Request $request){
        $data = $request->data;
        $uid = $request->uid;
        //$validFlag = $this->validDataIsNotNull($data);//验证数据是否有空
        $validFlag = true;
        if(!$validFlag){
            return $this->toJson(-2);
        }
        //$data = $this->getDataDelToken($data);
        $flag = $this->service->saveCompanyInfoById($uid,$data);
        if(!$flag){
            return $this->toJson(-100);
        }
        return $this->success();
    }
    /**
     * zwp
     * 获取法人证件和公司证件
     *  @param Request $request
     * @return array 
     */
    public function getLicences(Request $request){
        $uid = $request->uid;
        //$uid = 8;
        $data = $this->service->getLicencesById($uid);
        if(!$data){
            return $this->toJson(-3);
        }
        return $this->success($data);
    }
    
    /**
     * zwp
     * 保存证件
     * @param Request $request
     * @return array
     */
    public function saveLicences(Request $request){
        $data = $request->data;
        $uid = $request->uid;
        //$validFlag = $this->validDataIsNotNull($data);//验证数据是否有空
        $validFlag = true;
        if(!$validFlag){
            return $this->toJson(-2);
        }
        //$data = $this->getDataDelToken($data);
        $flag = $this->service->saveLicences($uid,$data);
        if(!$flag){
            return $this->toJson(-100);
        }
        return $this->success();
    }
    /**zwp,
     * 获取公司产品
     * @param Request $request
     * @return array
     */
    public function getCompanyProducts(Request $request){
        $uid = $request->uid;
        //$uid = 15;
        $cid = $this->service->getCid($uid);
        $data = $this->service->getCompanyProductsByCid($cid);
        //var_dump($data);exit();
        if(!$data){
            return $this->toJson(-3);
        }
        return $this->success($data);
    }
    /**
     * zwp
     * 保存公司产品
     * @param Request $request
     * @return type
     */
    public function saveCompanyProducts(Request $request){
        $data = $request->data;
        $uid = $request->uid;
        //$validFlag = $this->validDataIsNotNull($data);//验证数据是否有空
        $validFlag = true;
        if (!$validFlag) {
            return $this->toJson(-2);
        }
        //$data = $this->getDataDelToken($data);
        $flag = $this->service->saveCompanyProducts($uid,$data);
        if (!$flag) {
            return $this->toJson(-100);
        }
        return $this->success();
    }
    /**
     * zwp
     * 获取产品风格，先取对应uid的公司id，然后根据公司id取所有产品，再判断产品的cate，取出对应风格
     * @param Requst $request
     * @return type
     */
    public function getStyle(Request $request){
        $uid = $request->uid;
        //$uid = 8;
        //$cid = $this->service->getCid($uid);
        //$dataStyle = $this->service->getStyle($cid);
        //dd($dataStyle);exit();
        $styles = $this->service->getStyleByUid($uid);
        if(!$styles){
            return $this->toJson(-3);
        }
        return $this->success($styles);
    }
    
    public function saveStyle(Request $request){
        $data = $request->data;
        $uid = $request->uid;
        //$validFlag = $this->validDataIsNotNull($data);//验证数据是否有空
        $validFlag = true;
        if (!$validFlag) {
            return $this->toJson(-2);
        }
        //$data = $this->getDataDelToken($data);
        $flag = $this->service->saveStyle($uid,$data);
        if (!$flag) {
            return $this->toJson(-100);
        }
        return $this->success();
    }
    
    public function getProTypes(Request $request){
        $uid = $request->uid;
        //$uid = 66;
        $data = $this->service->getProTypes($uid);
        //var_dump($data);exit();
        if(!$data){
            return $this->toJson(-3);
        }
        return $this->success($data);
    }
    public function saveProTypes(Request $request){
        $data = $request->data;
        $uid = $request->uid;
        //$validFlag = $this->validDataIsNotNull($data);//验证数据是否有空
        $validFlag = true;
        if (!$validFlag) {
            return $this->toJson(-2);
        }
        //$data = $this->getDataDelToken($data);
        $flag = $this->service->saveProTypes($uid,$data);
        if (!$flag) {
            return $this->toJson(-100);
        }
        return $this->success();
    }

    public function getDesigns(Request $request){
        $uid = $request->uid;
        //$uid = 66;
        $data = $this->service->getDesigns($uid);
        if(!$data){
            return $this->toJson(-3);
        }
        return $this->success($data);
    }
    public function saveDesigns(Request $request){
        $data = $request->data;
        $uid = $request->uid;
        $flag = $this->service->saveDesigns($uid,$data);
        if (!$flag) {
            return $this->toJson(-100);
        }
        return $this->success();
    }
    public function getYields(Request $request){
        $uid = $request->uid;
        //$uid = 66;
        $data = $this->service->getYields($uid);
        if(!$data){
            return $this->toJson(-3);
        }
        return $this->success($data);
    }
    public function saveYields(Request $request){
        $uid = $request->uid;
        $data = $request->data;
        $flag = $this->service->saveYields($uid,$data);
        if (!$flag) {
            return $this->toJson(-100);
        }
        return $this->success();
    }
    public function getEnvs(Request $request){
        $uid = $request->uid;
        //$uid = 66;
        $data = $this->service->getEnvs($uid);
        if(!$data){
            return $this->toJson(-3);
        }
        return $this->success($data);
    }
    public function saveEnvs(Request $request){
        $uid = $request->uid;
        $data = $request->data;
        $flag = $this->service->saveEnvs($uid,$data);
        if (!$flag) {
            return $this->toJson(-100);
        }
        return $this->success();
    }
    
}
